package com.taptech.doufu.ui.adapter;

import android.view.View;

import java.util.ArrayList;
import java.util.List;

import androidx.viewpager.widget.PagerAdapter;
import androidx.viewpager.widget.ViewPager;

public class GuidePagerAdapter extends PagerAdapter {

	private ArrayList<View> views;
	private List<String> titleList;

	public GuidePagerAdapter(ArrayList<View> views,List<String> titleList) {
		this.views = views;
		this.titleList = titleList;
	}

	@Override
	public int getCount() {
		return this.views.size();
	}

	@Override
	public boolean isViewFromObject(View arg0, Object arg1) {
		return arg0 == arg1;
	}

	public void destroyItem(View container, int position, Object object) {
		((ViewPager) container).removeView(views.get(position));
	}

	// 页面view
	public Object instantiateItem(View container, int position) {
		((ViewPager) container).addView(views.get(position));
		return views.get(position);
	}

	@Override
	public CharSequence getPageTitle(int position) {
		if (titleList != null && titleList.size() > position) {
			return titleList.get(position);
		}
		return super.getPageTitle(position);
	}
}
